package com.djl.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.djl.ud.IUserDao;
import com.djl.ud.UserDao;
import com.djl.user.Users;

public class UserAddServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String userName = request.getParameter("userName");
		String name = request.getParameter("name");
		String pwd = request.getParameter("passWord");
		String sex = request.getParameter("sex");
		String year = request.getParameter("birthyear");
		String month = request.getParameter("birthmonth");
		String day = request.getParameter("birthday");
		String phone = request.getParameter("mobile");
		String address = request.getParameter("address");
		
		String bir = year+"-"+month+"-"+day;
		IUserDao dao = new UserDao();
		Users users = new Users();
		users.setUserid(userName);
		users.setUsername(name);
		users.setPassword(pwd);
		users.setSex(sex);
		users.setBirthday(bir);
		users.setPhone(phone);
		users.setAddress(address);
		users.setStatus(2);
		boolean b =false;
		try {
			b=dao.register(users);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(b){
			request.getRequestDispatcher("Lg").forward(request, response);
		}else{
			response.sendRedirect("error.jsp");
		}

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request, response);
	}

}
